<?php $post = $this->get('post');?>
<div class="x-list-title">
	<table width="100%" border="0" height="100%">
	<tr>
		<td align="left">
			<h2><?php _e($post['title']);?>
			</h2>
		</td>
		<td align="right">	
				<div class="x-list-options">
					<?php _e( tpl_search_form(baseUrl()."/Crm/Contract/Search", "#Crm/Contract/Search") );?>				
					<a onclick="load_inframe('<?php _baseUrl();?>/Crm/Bill/Add?contract_id=<?php _e(get('ID'));?>',{ title: 'Thanh toán hợp đồng'})" class="x-button">Thanh toán</a>
					<div class="x-options-container">
						<a class="x-button"> Tác vụ khác <span>&#9660;</span></a>
						<div class="x-options">
							<a href="#Crm/Contract/Edit?ID=<?php _e(get('ID'));?>" class="x-options-item">Sửa hợp đồng</a>
							<a onclick="module_delete('<?php _baseUrl();?>/Crm/Contract/Delete?ID[]=<?php _e(get('ID'));?>')" class="x-options-item">Xóa hợp đồng</a>
							<a href="#Crm/Contract/Add" class="x-options-item">Hợp đồng mới</a>
						</div>
					</div>
				</div>
		</td>
	</tr>
	</table>	
</div>
<div class="x-info-container">
	<table width="100%" border="0" class="x-info" cellspacing="0">
	<tr>
		<td colspan="4" align="right" class="x-info-top">
			<span class="tl">Thông tin chi chung</span>
			<span class="tr">Cập nhật lần cuối lúc <?php _e( show_date(DATETIME_FORMAT,$post['date_updated']) );?> bởi <?php _e(get_user_link( $post['updated_by_id'],$post['updated_by_name'],$post['updated_is_deleted']) );?></a></span>
		</td>
	</tr>
	<tr>
		<td class="x-info-label" nowrap="nowrap">
			Mã
		</td>
		<td class="x-info-content">
			<span class="code"><?php _e( $post['code'] );?></span>
		</td>
		<td class="x-info-label" nowrap="nowrap">
			Tên hợp đồng
		</td>
		<td class="x-info-content">
			<?php _e($post['title']);?>
		</td>	

	</tr>
	<tr>	
		<td class="x-info-label">
			Loại 
		</td>
		<td class="x-info-content">
			<a href="#Crm/Contract?parent_id=<?php _e( $post['parent_id'] );?>">
				<?php _e( $post['parent_title'] );?></a>
		</td>
		<td class="x-info-label" nowrap="nowrap">
			Ngày ký
		</td>
		<td class="x-info-content">
			<?php _e( show_date( DATE_FORMAT,$post['date_reg'] ) );?>						
		</td>	
	</tr>
	<tr>	
		<td class="x-info-label">
			Công ty
		</td>
		<td class="x-info-content">
			<a href="#Crm/Customer/View?ID=<?php _e( $post['customer_id'] );?>">
				<?php _e( $post['customer_name'] );?></a>
		</td>
		<td class="x-info-label" nowrap="nowrap">
			Giá trị
		</td>
		<td class="x-info-content">
			<?php _e(show_number($post['value']));?> <?php _e( $post['currency_symbol']);?>						
		</td>	
	</tr>
	<tr>
		<td class="x-info-label x-info-label-last">
			Mô tả
		</td>
		<td colspan="3" class="x-info-content">
			<?php _e( $post['desc'] );?>
		</td>
	</tr>
	<tr>
		<td class="x-info-label x-info-label-last">
			Đính kèm
		</td>
		<td colspan="3" class="x-info-content">
		<?php $a=array();?>
		<?php foreach( $this->get('files') as $f ):?>
		<?php show_thumb( $f, baseUrl()."/Crm/Contract/File?ID={$f['ID']}");?>
		<?php endforeach;?>	
		</td>
	</tr>
</table></div>
<div style="padding-top:5px">
<!--LIST-->
<?php $posts = $this->get('bills');?>
<table width="100%" class="x-list" cellpadding="0" cellspacing="0">
<tr>
	<th align="center" width="50">
		Lần
	</th>
	<th width="90" align="center">
		Ngày sự kiến
	</th>
	<th align="center" width="90">
		Ngày thực tế
	</th>
	<th align="center" width="50">
		%
	</th>
	<th align="center" width="150">
		Thành tiền
	</th>
	<th>
		Mô tả
	</th>
	<th align="center" width="50" colspan="2">Tác vụ</th>
</tr>	
<?php if( count($posts) == 0 ):?>
<tr>
<td colspan="10" class="page">
	<div class="x-page">
		Không tìm thấy bản ghi nào
	</div>
</td>
</tr>
<?php endif;?>
<?php foreach( $posts as $k => $a ):?>
<?php $vars = $this->get('vars');?>
<tr>
<td align="center">
	<?php _e($a['code']);?>
</td>				
<td align="center">
	<?php _e(show_date(DATE_FORMAT,$a['date_fixed']));?>
</td>

<td align="center">
	<?php _e(show_date(DATE_FORMAT,$a['date_paid']));?>
</td>

<td align="center">
	<?php _e($a['percent']);?>%
</td>

<td align="right">
	<?php _e(show_number($a['value']));?> <?php _e($a['currency_symbol']);?>
</td>

<td>
	<?php _e($a['desc']);?>
</td>

<td align="center" width="25">
	<?php $care_by_id = $this->get('care_by_id');?>
	<?php if( $this->hasRole('crm_admin') || $care_by_id == get_user_id()  ):?>
	<a onclick="module_delete('<?php _baseUrl()?>/Crm/Bill/Delete?ID[]=<?php _e($a['ID'])?>')" class="x-delete"></a>
	<?php else:?>
	<a class="x-nodelete"></a>
	<?php endif;?>
</td>
<td align="center" width="25">
	<?php if( $this->hasRole('crm_admin') || $care_by_id == get_user_id() ):?>
	<a onclick="load_inframe('<?php _baseUrl()?>/Crm/Bill/Edit?ID=<?php _e($a['ID'])?>')" class="x-edit"></a>
	<?php else:?>
	<a class="x-noedit"></a>
	<?php endif;?>
</td>	
</tr>
<?php endforeach;?>
</table></div>
<!-- END LIST-->